package com.moyun.finance.service;

import com.moyun.finance.entity.OrgDept;
import com.moyun.finance.entity.Response;
import com.moyun.finance.repository.OrgDeptRepository;
import com.moyun.finance.utils.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrgDeptService {
    @Autowired
    OrgDeptRepository odr;

    public Response save(OrgDept dept){
        dept.setId(BaseUtil.uuid());
        odr.save(dept);
        return new Response("添加成功!",true);
    }

    public Response update(OrgDept dept){
        odr.save(dept);
        return new Response("部门信息修改成功!",true);
    }

    public Response delete(OrgDept dept){
        odr.delete(dept);
        return new Response("部门删除成功",true);
    }

    //本公司所有部门
    public List<OrgDept> findAll(String companyId){
        List<OrgDept> depts =  odr.findByCompanyId(companyId);
        return depts;
    }

    public OrgDept findOneById(String deptId){
        return odr.findById(deptId).orElse(null);
    }
}
